package br.gendi.core;

import java.net.URL;
import java.util.Iterator;

import au.id.jericho.lib.html.FormField;
import au.id.jericho.lib.html.FormFields;
import au.id.jericho.lib.html.Source;

public class Parser {
	public static void main(String[] args) throws Exception {
		//String sourceUrlString="http://www.google.com/";
		String sourceUrlString = "http://www.cbs.dtu.dk/services/NetMHC/";
		if (args.length==0)
			System.err.println("Using default argument of \""+sourceUrlString+'"');
		else
			sourceUrlString=args[0];
		if (sourceUrlString.indexOf(':')==-1) 
			sourceUrlString="file:"+sourceUrlString;
		
		Source source=new Source(new URL(sourceUrlString));
		FormFields formFields=source.findFormFields();
		
	
		System.out.println("The document "+sourceUrlString+" contains "+formFields.size()+" form fields:\n");
		
		for (Iterator i=formFields.iterator(); i.hasNext();) {
			
			FormField formField=(FormField)i.next();
			//System.out.println(formField.getFormControl().getSource());
			System.out.println(formField);
			
			//System.out.println(formField.getName() + " --> " + formField.getFormControl());
			//System.out.println(formField.getDebugInfo());
		}
	}
}
